import Vue from 'vue'
// 1.引入路由
import VueRouter from 'vue-router'
// 引入使用到的页面组件...
import leftBar from '../components/LeftBar.vue'
import backLeftBar from '../components/back/BackLeftBar.vue'
// 2.使用VueRouter插件
Vue.use(VueRouter)
// 3.创建路由规则
const routes = [
    {
        path: "/", // 主页
        components: {
            leftBar: leftBar,
            content: () => import('../page/HomePage.vue')
        }
    },
    {
        path: "/article", // 文章页面
        components: {
            content: () => import('../page/ArticlePage.vue')
        }
    },
    {
        path: "/more", // 更多文章
        components: {
            leftBar: leftBar,
            content: () => import('../page/MorePage.vue')
        }
    },
    {
        path: "/aboutWeb", // 关于本站页面
        components: {
            leftBar: leftBar,
            content: () => import('../page/AboutWeb.vue')
        }
    },
    {
        path: "/resource", // 资源分享页面
        components: {
            leftBar: leftBar,
            content: () => import('../page/ResourceShare.vue')
        }
    },
    {
        path: "/announcement", // 公告页面
        components: {
            leftBar: leftBar,
            content: () => import('../page/AnnouncementPage.vue')
        }
    },
    {
        path: '/essay', // 随笔页面
        components: {
            leftBar: leftBar,
            content: () => import('../page/EssayPage.vue')
        }
    },
    {
        path: '/photo', // 图库页面
        components: {
            leftBar: leftBar,
            content: () => import('../page/PhotoPage.vue')
        }
    },
    {
        path: '/photoMore', // 图库更多页面
        components: {
            leftBar: leftBar,
            content: () => import('../page/PhotoMore.vue')
        }
    },
    {
        path: '/essayDetail', // 随笔详细页面
        components: {
            leftBar: leftBar,
            content: () => import('../page/EssayDetailPage.vue')
        }
    },
    {
        path: "/404", // 404页面
        components: {
            content: () => import('../page/NotFound.vue')
        }
    },
    // 后台
    {
        path: "/back", // 后台 数据页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/DataPage.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/article", // 后台 文章管理页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/ArticleManager.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/essay", // 后台 随笔管理页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/EssayManager.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/resource", // 后台 资源管理页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/ResourceManager.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/announcement", // 后台 公告管理页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/AnnouncementManagerPage.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/photo", // 后台 照片管理页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/PhotoManager.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/wish", // 后台心愿清单页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/WishManager.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/timer", // 后台时间卡片页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/TimerManager.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/back/administrator", // 后台管理员页面
        components: {
            leftBar: backLeftBar,
            content: () => import('../page/back/AdministratorPage.vue')
        },
        beforeEnter: (to, form, next) => {
            let token = sessionStorage.getItem('token') // 取token
            if (token === null || token === '') { // token为空则进入登录页面
                next({
                    path: '/backLogin'
                })
            } else {
                next() // 放行
            }
        }
    },
    {
        path: "/backLogin", // 后台登录页面
        components: {
            content: () => import('../page/back/backLogin.vue')
        },
    },
    {
        path: "*",
        redirect: "/404"
    }
]

// 4.创建路由对象，传入规则，并暴露
export default new VueRouter({
    routes,
    // mode: 'history',
})


